package tmt.usercenter.web.service;

import com.tmt.datatable.editor.ext.fileinfo.DefaultFileInfoLoader;
import com.tmt.datatable.model.FileInfo;
import com.tmt.fileservice.IFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tmt.usercenter.web.plugin.editormodel.FileInfoFinder;

import javax.persistence.EntityManager;
import javax.persistence.Id;
import java.util.List;

/**
 * Created by ThreeManTeam on 2017/6/1.
 */
@Service
@Transactional
public class FilePropertyService {

    @Autowired
    private EntityManager entityManager;

    @Autowired
    private IFileService fileService;

    @Transactional(readOnly = true)
    public <T> List<FileInfo> getFileInfo(Class<T> entityClazz, Object entityId) {
        T obj = entityManager.find(entityClazz, entityId);
        FileInfoFinder fileInfoFinder = new FileInfoFinder(fileService);
        return DefaultFileInfoLoader.getFileInfo(obj, Id.class, null, true, fileInfoFinder);
    }

}
